package com.ruoyi.picture.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.picture.mapper.ActabMapper;
import com.ruoyi.picture.domain.Actab;
import com.ruoyi.picture.service.IActabService;

/**
 * actabService业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-15
 */
@Service
public class ActabServiceImpl implements IActabService 
{
    @Autowired
    private ActabMapper actabMapper;

    /**
     * 查询actab
     * 
     * @param id actab主键
     * @return actab
     */
    @Override
    public Actab selectActabById(Long id)
    {
        return actabMapper.selectActabById(id);
    }

    /**
     * 查询actab列表
     * 
     * @param actab actab
     * @return actab
     */
    @Override
    public List<Actab> selectActabList(Actab actab)
    {
        return actabMapper.selectActabList(actab);
    }

    /**
     * 新增actab
     * 
     * @param actab actab
     * @return 结果
     */
    @Override
    public int insertActab(Actab actab)
    {
        return actabMapper.insertActab(actab);
    }

    /**
     * 修改actab
     * 
     * @param actab actab
     * @return 结果
     */
    @Override
    public int updateActab(Actab actab)
    {
        return actabMapper.updateActab(actab);
    }

    /**
     * 批量删除actab
     * 
     * @param ids 需要删除的actab主键
     * @return 结果
     */
    @Override
    public int deleteActabByIds(Long[] ids)
    {
        return actabMapper.deleteActabByIds(ids);
    }

    /**
     * 删除actab信息
     * 
     * @param id actab主键
     * @return 结果
     */
    @Override
    public int deleteActabById(Long id)
    {
        return actabMapper.deleteActabById(id);
    }

    @Override
    public List<Actab> listTotast(Long id) {
        List<Actab> destinations = new ArrayList<>();
        while (id != null) {
            Actab dest = actabMapper.selectActabById(id);
            if (dest == null) {
                break;
            }
            destinations.add(dest);
            id = dest.getParentId();
        }
        Collections.reverse(destinations);
        return destinations;
    }
}
